-
Notifications
You must be signed in to change notification settings - Fork 703
fix: disable Unicode escaping in JSON output and correct Meta type assignment #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Modify writeResponse in server/stdio.go to use json.NewEncoder with SetEscapeHTML(false) - This prevents Unicode characters from being escaped to \uXXXX format - Maintains compatibility while improving readability for non-ASCII characters
- Fix type error where map[string]any was being assigned to *Meta - Create proper Meta struct with AdditionalFields from unmarshaled data - This resolves build errors in the Go compiler
WalkthroughThe changes update JSON handling in two areas: the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🧰 Additional context used🧠 Learnings (7)📓 Common learnings📚 Learning: tool responses from the mcp server shouldn't contain rawinputschema, which is why the unmarshaljson ...Applied to files:
📚 Learning: the tool struct in the mark3labs/mcp-go project should handle both inputschema and rawinputschema co...Applied to files:
📚 Learning: in go mcp server, servertool.tool field is only used for tool listing and indexing, not for tool exe...Applied to files:
📚 Learning: the tool struct in mark3labs/mcp-go handles both inputschema and rawinputschema formats. when unmars...Applied to files:
📚 Learning: in the mark3labs/mcp-go project, the mcpserver.capabilities field is a struct value (servercapabilit...Applied to files:
📚 Learning: in the mcp-go library, the getpromptparams.arguments field is of type map[string]string, not map[str...Applied to files:
🧬 Code Graph Analysis (1)mcp/tools.go (1)
🔇 Additional comments (3)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Summary
This PR fixes two issues in the mcp-go library:
\uXXXXformat in stdio transportCallToolResultunmarshalingChanges
1. Fix Unicode Escaping (
server/stdio.go)json.Marshal()withjson.NewEncoder()inwriteResponse()functionencoder.SetEscapeHTML(false)to disable HTML/Unicode escapingBefore:
{"user_input": "\\u4f60\\u597d\\uff0c\\u6211\\u53eb\\u6155\\u5bb9\\u79bb"} After: {"user_input": "你好,我叫慕容离"} 2. Fix Meta Type Assignment (mcp/tools.go) - Correct assignment of map[string]any to *Meta field in CallToolResult.UnmarshalJSON() - Create proper Meta struct with AdditionalFields from unmarshaled data - Resolves Go compiler type errors Impact - ✅ Non-breaking change: Maintains full backward compatibility - ✅ Improved readability: Unicode characters display naturally instead of escaped format - ✅ Fixes build errors: Resolves type assignment compilation issues - ✅ Protocol compliant: Maintains JSON-RPC 2.0 specification adherence Testing - Builds successfully without errors - JSON-RPC protocol functionality unchanged - Unicode characters render correctly in stdio output - Existing tests continue to pass Motivation Unicode escaping reduces readability for international users and applications working with non-ASCII text. This change makes MCP server outputs more human-readable while maintaining full protocol compatibility. The Meta type fix resolves compilation errors that prevent building applications using the library. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved handling of JSON responses to prevent unwanted HTML and Unicode escaping in output. * Enhanced processing of metadata fields for more consistent data structure after JSON decoding. <!-- end of auto-generated comment: release notes by coderabbit.ai -->